package com.sunb2b.service;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.sunb2b.dao.CategoryAttrDAO;
import com.sunb2b.dao.CategoryDAO;
import com.sunb2b.entity.Category;
import com.sunb2b.entity.CategoryAttr;

@Service
public class CategoryService {
    
    @Inject
    private CategoryDAO categoryDAO;
    @Inject
    private CategoryAttrDAO categoryAttrDAO;
    
    public List getSubCategories(String id){
        return categoryDAO.findSubCategories(id);
    }
    
    public List getAllCategories(){
    	return categoryDAO.findAll();
    }
    public Category getCategory(String id){
        return categoryDAO.findById(id);
    }
    
    public void save(Category category){
        categoryDAO.save(category);
    }
    
    public String getMaxSubId(String id){
    	String maxSubId = categoryDAO.getMaxSubId(id);
        if(maxSubId==null){
        	maxSubId = id + "100";
        }
        return maxSubId;
    }
    
    public void delete(String[] ids){
    	categoryDAO.delete(ids);
    }
    
    public void deleteAttr(CategoryAttr ca){
    	categoryAttrDAO.delete(ca);
    }
    
    public void addAttr(CategoryAttr ca){
    	categoryAttrDAO.save(ca);
    }
    
    public CategoryAttr getAttrById(int id){
    	return categoryAttrDAO.findById(id);
    }
    
}
